'''
The Barista User Interface for the coffee bar workflow (Winter Intensives Lab 5)

This is where you define the fields that appear on the screen (application) the barista
sees and tell WMP how this application (user interface) fits into the overall workflow.

Note:  the comments here assume you have already read through the comments
in CoffeeBackend.py and OrderTakerApplication.py and made your edits there.
'''

from frontend.roleApplication import RoleApplication
from frontend.form import Type

class BaristaApplication(RoleApplication):
    '''
    The BaristaApplication "class" is a collection of the "methods" (functions) that 
    define the elements of the barista application.  

    See the notes for each method to see what you need to do to get this application working.
    '''

    def __init__(self):
        '''
        This __init__ method is called automatically when we run the code in this file.
        
        As with the OrderTakerApplication there are two lines of code, both of which you will
        need to edit.
        
        The first line of code tells WMP which workflow and role this application is associated with.
        
        The second line of code tells WMP what kind of user interface is needed and where to
        find the code to build that interface.
        
        We will edit each of these lines of code in turn:
        
        Editing the First Line of Code
        ------------------------------
        To fix this line of code you need to replace "WorkflowName" and "RoleName" with the actual
        name you gave your workflow in CoffeeBackend and the actual name you gave the barista
        role (also in CoffeeBackend).
        
        Editing the Second Line of Code
        -------------------------------
        To fix the second line of code you need to make a couple of edits:
        
        First, you need to replace "TaskName" with the actual name
        you gave this task in CoffeeBackend.
        
        In OrderTakerApplication that was the only change you needed to make but
        BaristaApplication uses a different kind of interface because it needs to
        allow the user to select which order to work with.  This was not true
        for OrderTakerApplication because it is the first step in the workflow and
        does not need to reference any existing data.  This different treatment is
        indicated by the use of register_sink_step in the second line of code
        (as opposed to register_source_step).
        
        Because of this difference, there is an additional parameter to edit in this
        second line of code:  the name_fields parameter.
        
        The barista will be shown a list of pending orders.  Each order on the list
        will be identified by some kind of description taken from the data for that order.
        Typically the description would be the drink to prepare and perhaps the name
        of the customer.  The name_fields parameter allows you to define which fields
        are used to generate this description.
        
        As shown below this list of fields is contained in square brackets.  It should
        always start with the sequence field, which is a number generated by WMP for
        each order on the list.
         
        For Lab 5:  replace FieldName1 and FieldName2 below with the names of actual
        fields associated with the order.  You decided on these field names when you
        set up the form in the OrderTakerApplication.  Note that you can use just
        one field or more than three.  You should choose the fields you think the barista
        should see when looking at a list of orders. 
        '''
        super(BaristaApplication, self).__init__("WorkflowName", "RoleName") # use actual work flow name and role name
        
        # specify actual task name and name_fields:
        self.register_sink_step("TaskName", self.prepare_drink_form_creator, name_fields=["sequence", "FieldName1", "FieldName2"])

    def prepare_drink_form_creator(self, stepname, form):
        '''
        defines the data entry form for the barista application.
        
        This form appears once the barista selects one of the pending orders from a list.
        
        The form consists of three parts:
        
        1.  a label that describes this particular order.  this label should include one or more fields
        from the order data that was collected in OrderTakerApplication.  It could be the same fields
        you specified in the name_fields parameter in the init method above.  
        
        For Lab 5:  You should specify these fields by editing the fields= parameter for 
        the add_task_label function below.
        
        2.  a list of fields that the barista needs to enter or edit for this drink order.
        Note that you don't have to include any fields at all if there is no information you need
        to capture from the barista.  
        
        For Lab 5:  optionally add any fields or static text you want to include in the form.
        
        3.  a button that the barista clicks to indicate this order has been prepared.  This
        button is automatically generated by WMP.  Note that even if you don't include any
        new fields for the barista to fill in, he or she will still need to click this button
        to signal that the order is complete, at which point WMP will update the status of the order
        in the Spreadsheet.
        '''
        form.add_task_label(fields=["FieldName1","FieldName2"]) # use one or more fields from order to define label
        #  add any static labels or fields you want to include in this form

'''
As with the other Lab 5 files, this is the part of the file where we actually
use the code we just wrote.  The first line starts up the BaristaApplication.
The second line tells the new application that it should start interacting with the user.
'''  
if __name__ == '__main__':
    app = BaristaApplication()
    app.MainLoop()